﻿using AutoMapper;
using MediatR;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;
using S.Organization.API.Application.Command.SheepFarmCommand;
using System.ComponentModel.DataAnnotations;

namespace S.Organization.API.Application.CommandHandler.SheepFarmCommandHandler
{
    public class AddSheepFarmCommandHandler : IRequestHandler<AddSheepFarmCommand, int>
    {
         private readonly IBaseRepository<SheepFarmSetting> _repository;
        private readonly IMapper mapper;

        public AddSheepFarmCommandHandler(IBaseRepository<SheepFarmSetting> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddSheepFarmCommand request, CancellationToken cancellationToken)
        {
            request.FarmNumber = DateTime.Now.ToString("yyyyMMddHHmmssfffff");
            request.CreateBy = "张三";
            request.CreateDate = DateTime.Now;
            return await _repository.CreateAsync(mapper.Map<SheepFarmSetting>(request));
        }


    }
}
